<!DOCTYPE HTML>
<html>
<head>
<title>If Var [not] between LowerBound and UpperBound | AutoHotkey</title>
<meta name="description" content="The "if Var between Low and High" statement checks whether a variable's contents are numerically or alphabetically between two values (inclusive)." />
<meta name="ahk:equiv-v2" content="commands/If.htm" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>If var [not] between LowerBound and UpperBound</h1>

<p>根据数值或字母顺序检查<a href="../Variables.htm">变量的</a>内容是否在两个值之间(包含边界).</p>

<pre class="Syntax">
<span class="func">if</span> Var <span class="func">between</span> LowerBound <span class="func">and</span> UpperBound
<span class="func">if</span> Var <span class="func">not between</span> LowerBound <span class="func">and</span> UpperBound
</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Var</dt>
  <dd><p>需要被检查的<a href="../Variables.htm">变量</a>名称.</p></dd>

  <dt>LowerBound</dt>
  <dd><p>指定范围的下限, <em>Var</em> 必须大于或等于此字符串, 数字或变量引用.</p></dd>

  <dt>UpperBound</dt>
  <dd><p>指定范围的上限, <em>Var</em> 必须小于或等于此字符串, 数字或变量引用.</p></dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>如果这三个参数都为纯数值, 那么它们将被作为数字而不是字符串进行比较. 其他情况下, 它们将被作为字符串按字母顺序进行比较(即字母次序将决定 <em>Var</em> 是否在指定范围内). 此时, 可以使用 <code><a href="StringCaseSense.htm">StringCaseSense</a> On</code> 来设置在比较时区分大小写.</p>
<p>运算符 "between" 不支持用于<a href="../Variables.htm#Expressions">表达式</a>中. 相反, 使用 <a href="IfExpression.htm">If 语句</a>, 如 <code>if (Var &gt;= LowerBound and Var &lt;= UpperBound)</code> 来模拟这个操作符的行为.</p>
<h2 id="Related">相关</h2>
<p><a href="IfEqual.htm">IfEqual/Greater/Less</a>, <a href="IfIn.htm">if var in/contains MatchList</a>, <a href="IfIs.htm">if var is type</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="EnvAdd.htm">EnvAdd</a><a href="Block.htm">, 区块</a>, <a href="Else.htm">Else</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExInteger">
<p><a class="ex_number" href="#ExInteger"></a> 检查 <var>var</var> 是否在 1 到 5 的范围内.</p>
<pre>if var between 1 and 5
    MsgBox, %var% is in the range 1 to 5, inclusive.</pre>
</div>

<div class="ex" id="ExFloat">
<p><a class="ex_number" href="#ExFloat"></a> 检查 <var>var</var> 是否在 0.0 到 1.0 的范围内.</p>
<pre>if var not between 0.0 and 1.0
    MsgBox %var% is not in the range 0.0 to 1.0, inclusive.</pre>
</div>

<div class="ex" id="ExVar">
<p><a class="ex_number" href="#ExVar"></a> 检查 <var>var</var> 是否在 <var>VarLow</var> 和 <var>VarHigh</var>(包含) 之间.</p>
<pre>if var between %VarLow% and %VarHigh%
    MsgBox %var% is between %VarLow% and %VarHigh%.</pre>
</div>

<div class="ex" id="ExString">
<p><a class="ex_number" href="#ExString"></a> 检查 <var>var</var> 是否介于蓝色和红色之间(包含).</p>
<pre>if var between blue and red
    MsgBox %var% is alphabetically between the words blue and red.</pre>
</div>

<div class="ex" id="ExInputBox">
<p><a class="ex_number" href="#ExInputBox"></a> 允许用户输入一个数字, 并检查它是否在 1 到 10 的范围内.</p>
<pre>LowerLimit := 1
UpperLimit := 10
InputBox, UserInput, Enter a number between %LowerLimit% and %UpperLimit%
if UserInput not between %LowerLimit% and %UpperLimit%
    MsgBox Your input is not within the valid range.</pre>
</div>

</body>
</html>